<script setup lang="ts">
import {getStudentExamArrange} from "/@/api/hbmy_wx/examArrange";
import {Toast} from "vant";

onMounted(async () => {
  const res = await getStudentExamArrange()
  const error = res.response.value.extend.error
  if (error === '暂无考试安排'){
    Toast('暂无考试安排')
    return
  }else {
    examsList.value = JSON.parse(res.response.value.extend.exams)
    examsList.value = examsList.value.map(item => {
      // 使用正则表达式匹配日期和时间
      const regex = /(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})--(\d{2}:\d{2})/;
      const match = item.testTime.match(regex);

      if (match) {
        // 更新对象的属性
        item.startDate = match[1];
        item.startTime = match[2];
        item.endTime = match[3];
      }
      return item;
    });
  }
})
const msg = ref()
const activeName = ref([])
const examsList = ref([])
</script>

<template>
  <Header title="考试安排"></Header>
  <van-collapse v-model="activeName" ref="collapseRef">
    <van-collapse-item
        style="margin-top: 10px; padding:0 10px;"
        v-for="exam in examsList"
        :name="exam.num"
        :is-link="false"
        :readonly="true"
        size="large">
      <template #title>
        <span style="height:100%;line-height: 3vh; border-left: 5px solid #1989fa; margin-right: 5px"></span>
        {{exam.courseName}}
      </template>
      <template #label>
        <p style="margin-top: 15px">{{ exam.startDate }} {{ exam.startTime }}-{{ exam.endTime }}</p>
      </template>
      <template #value>
        <div style="margin-top: 13px">
          {{exam.roomName}}
        </div>
      </template>
    </van-collapse-item>
  </van-collapse>

</template>

<style scoped lang="less">

</style>
